Grid Topology
No matter what analysis operations you are performing on the data, visualization of the geometric elements of an unstructured grid (i.e. nodes, edges) without any data mapped to them can always be useful for a number of reasons, including but not limited to understanding the mesh topology and diagnosing patterns or issues with or prior to data analysis (e.g. analyzing the mesh of a dynamical core prior to running a simulation).
UXarray provides convenient functionality to visualize these elements of the Grid object. Below we will introduce those functions, but let us do the initial setup first:
Setup
This setup handles the package imports and data loading.
Imports
import uxarray as ux
# General Plotting
import cartopy.crs as ccrs
# Plotting with HoloViz
import holoviews as hv
from holoviews import opts
import geoviews.feature as gf
/home/runner/miniconda3/envs/cookbook-dev/lib/python3.10/site-packages/dask/dataframe/_pyarrow_compat.py:17: FutureWarning: Minimal version of pyarrow will soon be increased to 14.0.1. You are using 12.0.1. Please consider upgrading.
warnings.warn(
Read in the data
# File paths
file_dir = "../../meshfiles/"
grid_filename = "oQU120.grid.nc"
data_filename = "oQU120.data.nc"
# A standalone grid can be opened for immediate visualization
ux_grid = ux.open_grid(file_dir + grid_filename)
# Visualization through a `UxDataset`'s associated grid, `uxds.uxgrid` is also possible.
uxds = ux.open_dataset(file_dir + grid_filename, file_dir + data_filename)
How to plot through Grid, UxDataset, or UxDataArray?
As the above ux_grid and uxds creation suggests, you may either have a UxDataset (or similarly UxDataArray), or a standalone Grid object. Visualization
of the geometric elements of an unstructured grid is possible in all of these cases as follows (Through uxgrid accessor when it is a UxDataset or UxDataArray):
uxarray.Grid.plot.plotting_function()
uxarray.UxDataset.uxgrid.plot.plotting_function()
uxarray.UxDataArray.uxgrid.plot.plotting_function()
We will demonstrate plotting functions using the standalone ux_grid thorughout this notebook.
Plotting Edges
Plotting the edges of an Unstructured Grid gives us an immediate idea of what the actual mesh looks like since connected edges construct the faces of the grid. Because of this, edge visualization is considered as the default method for Grid topology visualization purposes, and the default plotting method uxarray.Grid.plot(), provides an edge plot as follows:
ux_grid.plot(title="Default Grid Plot Method", xlim=(-170,-50), ylim=(10, 80), width=700, height=350)